package org.jeecg.modules.educational.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.education.entity.Education;
import org.jeecg.modules.education.service.EducationService;
import org.jeecg.modules.educational.entity.EducationMessage;
import org.jeecg.modules.educational.service.EducationMessageService;
import org.jeecg.modules.project.entity.Project;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liujiamiao
 * @since 2020-11-06
 */
@Validated
@RestController
@RequestMapping("/educational/education-message")
public class EducationMessageController {

    @Autowired
    private EducationMessageService educationService;

    @ApiOperation(value = "分页查询")
    @PostMapping("/list/{page}/{limit}/{basicId}")
    public Result list(@ApiParam("第几页") @PathVariable("page")Integer page,
                       @ApiParam("分页的数量") @PathVariable("limit") Integer limit,
                       @ApiParam("基本信息id") @PathVariable("basicId") Integer basicId){
        IPage<EducationMessage> pageList = educationService.pageSelect(page,limit,basicId);
        return Result.ok(pageList);
    }

    @ApiOperation("保存/更新教育经历")
    @PostMapping("/save")
    public Result save(@Valid @ApiParam("教育经历json数据") @RequestBody EducationMessage education){
        educationService.saveOrUpdate(education);
        return Result.ok();
    }

    @ApiOperation("删除该教育经历")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@ApiParam("教育经历id") @PathVariable("id") Integer id){
        educationService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("更新教育经历")
    @PutMapping("/update")
    public Result updaate(@ApiParam("json实体类数据") @RequestBody EducationMessage education){
        educationService.updateById(education);
        return Result.ok();
    }

    @ApiOperation("根据教育经历id获取项目信息")
    @GetMapping("/info/{id}")
    public Result info(@ApiParam("教育经历id") @PathVariable Integer id){
        EducationMessage education = educationService.getById(id);
        return Result.ok(education);
    }


}

